import {
  AD_TYPE,
  DEVICE_TYPE,
  ORIENTATION_TYPE,
  NETWORK_TYPE
} from '../setting'
export default function(params, info, ua) {
  // console.log(info)
  const sdkInfo = {
    sdk_version: '1.0.0',
    version: '3.0'
  }
  const device = info[0].data || info[0]
  const deviceInfo = {
    device_brand: device.brand, //设备名称
    device_model: device.model, //设备型号
    device_density: device.screenDensity, //设备屏幕密度
    device_width: device.screenWidth, //设备宽度
    device_height: device.screenHeight, //设备高度
    device_type: DEVICE_TYPE[device.deviceType] || 0, // 设备类型,phone
    device_os: 'Android',
    device_apiLevel: device.osVersionCode, //操作系统版本名称
    device_rom_version: device.platformVersionCode, //运行平台版本号
    device_type_os: device.osVersionName, //安卓系统的版本号,
    language: device.language //系统语言
  }
  const installAppList = {
    device_app_list: info[1]
      .filter(item => item.result !== undefined)
      .map(item => item.result)
      .join('')
  }

  const battery = {
    device_battery_level: Math.round(info[2].level * 100)
  }
  const location = {
    device_conuntry: 'CN'
  }
  const deviceId = {
    device_imsi: 46000, //网络运营商
    device_adid: info[3][0].userId
      ? info[3][0].userId.slice(0, 16)
      : info[3][0].userId, //Android id
    device_oaid: info[3][1].oaid, //oaid
    device_imei:
      info[3][2].deviceId && /^\d+$/.test(info[3][2].deviceId)
        ? info[3][2].deviceId
        : '' // 设备唯一标识, imei或meid,或者oaid
  }
  const network = {
    device_network: NETWORK_TYPE[info[4][0].type] || -1
  }
  const appInfo = {
    app_package: info[5].package, // 包名称
    app_name: info[5].name, //快应用名称
    app_ver: info[5].versionCode, //快应用版本
    device_orientation:
      info[5].display && info[5].display.orientation
        ? ORIENTATION_TYPE[info[5].display.orientation] || -1
        : -1
  }
  const adData = {
    accept_ad_type: AD_TYPE[params.type],
    pid: params.pid,
    deny_cats: params.deny_cats,
    deny_ader_ids: params.deny_ader_ids,
    deny_cids: params.deny_cids,
    ext: { features: [{ value: ['1'], key: 'hap' }] },
    h5_app_type: 1
  }
  const deviceUa = {
    device_ua: ua
  }
  return {
    ...deviceInfo,
    ...deviceId,
    ...network,
    ...installAppList,
    ...sdkInfo,
    ...appInfo,
    ...battery,
    ...adData,
    ...deviceUa
  }
}
